#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXN=1e3+10,MAXM=1e4+10;
int n,m,p,head[MAXN],cnt,ans=-1,d[MAXN];
bool vis[MAXN];
struct edge
{
	int v,next,val;
}e[MAXM*2];
int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
void addedge(int x,int y,int z)
{
	e[++cnt]=(edge){y,head[x],z};
	head[x]=cnt;
	return;
}
bool SPFA(int x)
{
	memset(d,0x3f3f3f3f,sizeof(d));
	memset(vis,0,sizeof(vis));
	queue<int>q;
	q.push(1);
	vis[1]=true;
	d[1]=0;
	while(!q.empty())
	{
		int u=q.front();q.pop();
		vis[u]=false;
		for(int i=head[u];i;i=e[i].next)
		{
			int v=e[i].v;
			if(d[u]+(e[i].val>x)<d[v])
			{
				d[v]=d[u]+(e[i].val>x);
				if(!vis[v])
				{
					q.push(v);
					vis[v]=true;
				}
			}
		}
	}
	return d[n]<=p;
}
int main()
{
	n=read();m=read();p=read();
	for(int i=1;i<=m;++i)
	{
		int x=read(),y=read(),z=read();
		addedge(x,y,z);
		addedge(y,x,z);
	}
	int l=0,r=1e9;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(SPFA(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}
